This repository was archived by the owner on Oct 16, 2025. It is now read-only.
fix: reject pending getLatestBlock requests when block tracker is stopped#320
Merged
cryptodev-2s merged 2 commits intomainfrom May 28, 2025
Merged
Conversation
11f01ed to
2d8f3ba
Compare
cryptodev-2s
commented
May 28, 2025
| // play: one to go to the next iteration of the block tracker | ||
| // loop, another to expire the current block number cache. We don't | ||
| // know which one has been added first, so we have to find it. | ||
| blockTracker.removeAllListeners(); |
Contributor
Author
There was a problem hiding this comment.
I had to restart the block tracker to clear the cached currentBlock.
cryptodev-2s
commented
May 28, 2025
Comment on lines
+888
to
+901
| // Verify that the block reset timeout is set up | ||
| expect( | ||
| setTimeoutRecorder.calls.some((call) => { | ||
| return call.duration === blockTrackerOptions.blockResetDuration; | ||
| }), | ||
| ).toBe(true); | ||
|
|
||
| // Wait for the block reset timeout to complete | ||
| await setTimeoutRecorder.nextMatchingDuration( | ||
| blockTrackerOptions.blockResetDuration, | ||
| ); | ||
|
|
||
| // Verify that the current block is still null after the timeout | ||
| expect(blockTracker.getCurrentBlock()).toBeNull(); |
Contributor
Author
There was a problem hiding this comment.
Not really tied to the test and thus can be removed
2d8f3ba to
acce3c3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug where
getLatestBlock()promises could hang indefinitely when the block tracker is stopped before the request completes.Reference
Fixes #319
Problem
The
#pendingLatestBlockprivate instance variable tracks pending requests for the latest block. However, when the polling loop is stopped (viaremoveAllListeners()or similar), any pendinggetLatestBlock()promises would never resolve, causing:destroy()methodSolution
Modified the
_maybeEnd()method to call#rejectPendingLatestBlock()when the block tracker is stopped, ensuring that any pendinggetLatestBlock()requests are properly rejected with a "Block tracker destroyed" error.Steps to Reproduce the Bug
getLatestBlock()getLatestBlock()would hang forever ❌After Fix
The
getLatestBlock()promise is now properly rejected with "Block tracker destroyed" error ✅